/*
 * 电子圈业务统计Javascript代码
 * 参数说明:
 * 		var cid:	按照一定规则记录不同页面<%= %>
 * 		var data:	电子圈url地址后面的参数(比如说qid,tagname) <%= %>
 * 		var uid: 	用户Id,在Session取得
 * 		var sid: 	session,在Session取得,之前的时间戳
 * @author: Vernon.Chen
 * @date: 2012-07-05
 */
var REPORT_OBJ = {} ;

(function(){
  	function report(){
	    this.rt = {};
	}
	
  	report.prototype = {
		getCid : function() {
			if (typeof __STAT_CID != "undefined") {
				this.rt.cid = __STAT_CID;
			}else{
				this.rt.cid = 'w' ;
			}
		},
		getData : function() {
			if (typeof __STAT_DATA != "undefined") {
				this.rt.data = __STAT_DATA;
			}else{
				this.rt.data = "" ;
			}
		},
		getUid : function() {
			var uid = this.getCookie('UID');
			if (uid != false) {
				this.rt.uid = uid;
			} else {
				this.rt.uid = 0;
			}
		},
		getSid : function() {
			sid = this.getCookie('LID');
			if (sid != false) {
				this.rt.sid = Math.round(sid/1000);
			}else{
				this.rt.sid = "";
			}
		},
		
		/** tool function * */
		getRnd : function() {
			return Math.round(Math.random() * 100000);
		},
		getCookie : function(k) {
			var strCookie = document.cookie;
			var arrCookie = strCookie.split("; ");
			for ( var i = 0; i < arrCookie.length; i++) {
				var arr = arrCookie[i].split("=");
				if (arr[0] == k) {
					if (arr[1] != null) {
						return arr[1].split("-")[0];
					}
				}
			}
			return false;
		},
		
		/**  */
		init: function() {
		    this.getCid();
		    this.getData();
		    this.getUid();
		    this.getSid();
		},
		send : function() {
			var sendUrl = 'http://stat.dianziq.com/v1';
			this.init(); // 获取数据
			var image = new Image(1, 1);
			var src = sendUrl + '?cid=' + this.rt.cid + '&data='
					+ encodeURIComponent(this.rt.data) + '&uid=' + this.rt.uid
					+ '&sid=' + this.rt.sid + '&times=' + this.getRnd();
			image.src = src;
		}

	};
	
	// 执行js代码
	var y = new report();
	REPORT_OBJ.m = y;
	y.send();
})();
